package reflect;

import java.lang.reflect.Method;

/**
 * 自动调用Person类中所有以s开头的无参方法
 */
public class Tsst1 {
    public static void main(String[] args) throws Exception{
        Class<?> aClass = Class.forName("reflect.Person");
        Object o = aClass.newInstance();
        Method[] methods = aClass.getDeclaredMethods();


        for (Method method : methods) {
            if (method.getName().startsWith("s") && method.getParameterCount() == 0){
                method.setAccessible(true);
                method.invoke(o);
            }
        }

    }
}
